import { request } from '../request';

/* 文章主体内容 */
export function articleData(params: { id: string }) {
  return request<
    {
      category: Api.Category;
      tagList: Api.TagInfo[];
      readTime: string;
      relativeTime: string;
      content: string;
      totalWords: string;
      userInfo: {
        id: string;
        username: string;
        avatar: string;
        summary: string;
        fansNum: number;
        favUserNum: number;
        followFlag: boolean;
      };
      topic: Api.TopicInfo;
      isStar: boolean;
      isFav: boolean;
    } & Api.Article
  >({
    url: '/article/data',
    method: 'post',
    data: params,
  });
}

/* 文章收藏/取消收藏 */
export function articleFavorites(params: { articleId: string }) {
  return request<boolean>({
    url: '/article/favorites',
    method: 'post',
    data: params,
  });
}

/* 文章点赞/取消点赞 */
export function articleStar(params: { articleId: string }) {
  return request<boolean>({
    url: '/article/star',
    method: 'post',
    data: params,
  });
}

/* 推荐阅读列表 */
export function articleRecommend(params: { id: string }) {
  return request<
    Array<
      {
        category: Api.Category;
        topic: { id: string; name: string };
        tagInfoList: Api.TagInfo[];
        relativeTime: Api.UserInfo;
      } & Api.Article
    >
  >({
    url: '/article/recommend',
    method: 'post',
    data: params,
  });
}
